<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>鼠标移入移出事件</title>
  <style>
    .demo {
      width: 100%;
      height: 300px;
      background-color: lightcoral;
    }

    p {
      color: limegreen;
    }

  </style>
</head>

<body>
  <div class="pc" id="app">
    <h1>移入修改内容</h1>
    <h1>{{ msg }}</h1>
    <div class="demo" @mouseover="mouseOver" @mouseleave="mouseLeave" :style="active">
      <p ref="acp">我是内容</p>
    </div>


    <h1>移入移出鼠标发生改变</h1>
    <div>
      <ul>
        <li v-on:mousemove="addClass($event)" @mouseout="addClass2($event)">喜剧片</li>
        <li v-on:mousemove="addClass($event)" @mouseout="addClass2($event)">恐怖片</li>
        <li v-on:mousemove="addClass($event)" @mouseout="addClass2($event)">爱情片</li>
        <li v-on:mousemove="addClass($event)" @mouseout="addClass2($event)">动作片</li>
      </ul>
    </div>
  </div>

  <!-- VUE导入 -->
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    var app = new Vue({
      el: "#app",
      data: {
        msg: "HelloWorld,I am PC",
        active: "",
      },
      methods: {
        // 移入
        mouseOver() {
          this.active = "background-color:black";
          // 操作dom 获取p标签改变其样式
          var acps = this.$refs.acp
          acps.style.color = "red"
        },
        // 移出
        mouseLeave() {
          this.active = "";
          this.$refs.acp.style = ''
        },

        addClass: function (event) {
        //   this.current = index;
          //获取点击对象      
          var el = event.currentTarget;
          el.style.backgroundColor= "pink";
          console.log(el);
          console.log("当前对象的内容：" + el.innerHTML);
        },
        addClass2: function (event) {
        //   this.current = index;
          //获取点击对象      
          var el = event.currentTarget;
          el.style.backgroundColor= "";
        },

      }
    })

  </script>
</body>

</html>
